<?php
/**
 * RPC Message
 * 
 * @category	XML
 * @package		dayscript.xml.rpc
 * @subpackage	
 * @author		Nelson Daza <ndaza@dayscript.com>
 * @copyright	2009 Dayscript Ltda.
 * @license		
 * @version		1.0
 * @version		$Revision: 0 $
 * @filesource	
 * @link		http://www.dayscript.com
 * @link		{docsLink}
 * @uses		
 * @since		1.0
 * @modifiedby	$LastChangedBy: Nelson Daza $
 * @modified	$Date: 2009-08-13 $
 */

namespace dayscript\xml\rpc;

/**
 * RPC Message
 *
 * @category	XML
 * @package		dayscript.xml.rpc
 * @subpackage	
 * @author		Nelson Daza <ndaza@dayscript.com>
 * @copyright	2009 Dayscript Ltda.
 * @license		
 * @version		1.0
 * @link		http://www.dayscript.com
 * @link		{docsLink}
 * @uses		
 * @since		1.0
 * @modifiedby	$LastChangedBy: Nelson Daza $
 * @modified	$Date: 2009-09-14 $
 */
class Request	{
	/**
	 * Request method name 
	 * @var string $method
	 */
	private $method;
	/**
	 * Method's arguments 
	 * @var array $args
	 */
	private $args;
	/**
	 * XML representation of the request
	 * @var string $xml
	 */
	private $xml;
	/**
	 * Request contructor 
	 * @param string $method
	 * @param array $args
	 * @return Request
	 */
	function __construct( $method, $args = null )	{
		$this->method = $method;
		$this->args = ( \is_array( $args ) ? $args : array( $args ) );
		$this->xml = '<?xml version="1.0"?><methodCall><methodName>' . $this->method . '</methodName><params>';
		foreach ( $this->args as $value )	{
			if( $value !== null )	{
				$RPCValue = new \dayscript\xml\rpc\data\Value( $value );
				$this->xml .= '<param><value>' . $RPCValue->getXML( ) . '</value></param>';
			}
		}
		$this->xml .= '</params></methodCall>';
	}
	/**
	 * Request length
	 * @return int $length
	 */
	function getLength( )	{
		return \strlen( $this->xml );
	}
	/**
	 * Returns an XML representation of the request 
	 * @return string $xml
	 */
	function getXml( )	{
		return $this->xml;
	}
}
